home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
cdity
/
ModeProSrc.lha
/
MPFiles.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-08-29
|
8KB
|
235 lines
#include "MPFiles.h"
//extern UWORD defaultpens[];
extern WORD NumDriPens;
extern struct MPSem *MPSem;
void ReadChunk(struct ParseChunk *PC,APTR Dest,ULONG Size);
STRPTR ReadChunkString(struct ParseChunk *PC);
struct ParseChunk
{
UBYTE *Data;
};
BOOL LoadFile(struct List *List, UBYTE *fname)
{
LONG bdsize;
UBYTE *bddatastart;
struct IFFHandle *iff;
struct CollectionItem *ci,*cip;
struct StoredProperty *sp;
LONG error=0;
struct ParseChunk pc;
struct DefaultNode *n;
struct Promo pm;
LONG numpens,pen;
UWORD font; // Don't Change Type
ULONG flags;
if(iff=AllocIFF())
{
if(iff->iff_Stream = Open (fname,MODE_OLDFILE))
{
InitIFFasDOS(iff);
if(!(error=OpenIFF(iff,IFFF_READ)) )
{
if (!(error=CollectionChunk(iff,ID_PREF,ID_PRMO)))
{
if (!(error=PropChunk(iff,ID_PREF,ID_MPPR)))
{
if(!(error=StopOnExit(iff,ID_PREF,ID_FORM)))
{
if((error=ParseIFF(iff,IFFPARSE_SCAN))>-3)
{
error=0;
if(sp=FindProp(iff,ID_PREF,ID_MPPR))
{
struct MPPR_Chunk *mppr;
mppr=(struct MPPR_Chunk *)sp->sp_Data;
MPSem->Enabled =mppr->EnablePromotion;
MPSem->EnabledNLM =mppr->EnableNLM;
MPSem->CenterAll =mppr->CenterUnknown;
MPSem->CatchScreens =mppr->AskUnknown;
if(mppr->Version>0)
MPSem->CatchPubScreens =mppr->AskUnknownPub;
}
ci=FindCollection(iff,ID_PREF,ID_PRMO);
cip=ci;
while(cip!=NULL && error>=0)
{
if(n=AllocDefaultNode(0))
{
pc.Data=(UBYTE *)cip->ci_Data;
ReadChunk(&pc,&pm,sizeof(struct Promo));
n->Type =pm.Type;
n->ModeSelect =pm.ModeSelect;
n->ModeID =pm.ModeID;
n->Width =pm.Width;
n->Height =pm.Height;
n->OverscanType =pm.OverscanType;
n->AutoScroll =pm.AutoScroll;
n->Look3D =pm.Look3D;
n->Def_Node.ln_Name=ReadChunkString(&pc);
if(pm.Version>0)
{
ReadChunk(&pc,&numpens,sizeof(numpens));
ReadChunk(&pc,&n->Pens[0] ,sizeof(UWORD)*min(DRIPENS,numpens));
for(pen=numpens;pen<DRIPENS;pen++)
n->Pens[pen]=0;//defaultpens[pen];
numpens-=DRIPENS;
if(numpens>0)
{
ReadChunk(&pc,0 ,sizeof(UWORD)*numpens);
}
if(pm.Version>1 && !error)
{
ReadChunk(&pc,&flags,sizeof(flags));
n->Flags=flags;
if(n->Flags & CENTER)
{
n->Flags&=(~CENTER); // clear obsolete flag.
n->CenterFlags = 3; // set new flag.
}
ReadChunk(&pc,&font,sizeof(font));
n->FontType=font;
if(n->FontType==SFONT_MP)
{
n->Font.tta_Name=ReadChunkString(&pc);
ReadChunk(&pc,&n->Font.tta_YSize,4);//<-'4'=TextAttr struct less ta_Name
}
if(pm.Version>2 && !error)
{
ReadChunk(&pc,&n->PubOptions,4);
n->PubName=ReadChunkString(&pc);
if(pm.Version>3 && !error)
{
ReadChunk(&pc,&n->Depth,2);
n->LockedPens=ReadChunkString(&pc);
if(pm.Version>4 && !error)
{ // Version 5
n->HotKey=ReadChunkString(&pc);
}
if(pm.Version>5 && !error)
{ // Version 6
ReadChunk(&pc,&n->OrigDisplayID,sizeof(ULONG));
}
if(pm.Version>6 && !error)
{ // Version 7
ReadChunk(&pc,&n->ODFlags,sizeof(UBYTE)*2);
ReadChunk(&pc,&n->Colors,sizeof(ULONG));
if(n->Colors)
{
if(n->Palette=AllocVec(sizeof(struct RGB)*n->Colors,MEMF_PUBLIC))
{
ReadChunk(&pc,n->Palette,sizeof(struct RGB)*n->Colors);
}
else
error=TRUE;
}
if(pm.Version>7 && !error)
{ // Version 8
ReadChunk(&pc,&n->BackdropType, sizeof(UWORD)); // loads BackdropFlags aswell
if(!n->BackdropType) // handle old versions of file
n->BackdropType=(n->BackdropFlags & BF_ON ? 1:0);
//n->BackdropFlags&=~BF_ON;
n->BackdropFile=ReadChunkString(&pc);
if(pm.Version>8 && !error)
{ // Version 9
ReadChunk(&pc,&bdsize, sizeof(bdsize));
bddatastart=pc.Data;
switch(n->BackdropType)
{
case 2: //RGB
ReadChunk(&pc,&n->BackdropRGB, sizeof(struct RGB));
bdsize-=sizeof(struct RGB);
break;
}
// set Data ptr to right place
pc.Data=bddatastart+bdsize;
}
}
}
}
}
}
}
else
for(pen=0;pen<NumDriPens;pen++)
n->Pens[pen]=0;//defaultpens[pen];
if(error)
FreeDNode(n);
else
if(pm.Type<NUM_LISTS)
AddHead(&List[pm.Type],(struct Node *)n);
else
FreeDNode(n);
}
else
error=-1;
cip=cip->ci_Next;
}/* end while */
}/* end ParseIFF if */
}
} /* End Prop MPPR */
}/* End Collect PRMO */
CloseIFF(iff);
}
Close(iff->iff_Stream);
}
FreeIFF(iff);
}
if(error<0)
return(FALSE);
else
return(TRUE);
}
void ReadChunk(struct ParseChunk *PC,APTR Dest,ULONG Size)
{
if(PC)
{
if(Dest && PC->Data && Size)
{
CopyMem((APTR)PC->Data,(APTR)Dest,Size);
}
PC->Data+=Size;
}
}
STRPTR ReadChunkString(struct ParseChunk *PC)
{
STRPTR str=0;
ULONG size;
if(PC)
{
size=strlen(PC->Data)+1;
str=AllocVec(size,MEMF_PUBLIC|MEMF_CLEAR);
if(PC->Data && size)
CopyMem((APTR)PC->Data,(APTR)str,size);
if(size & 1)
size++;
PC->Data+=size;
}
return(str);
}